package com.gg.user.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.gg.beanhelper.BeanHelper;
import com.gg.entity.User;
import com.gg.user.service.UserService;

import base.BaseServlet;


@WebServlet("/user/RegistServlet")
public class RegistServlet extends BaseServlet {
	@Autowired
	private  UserService  userService;
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User  user =  BeanHelper.getBean(request.getParameterMap(), User.class);
		//让email 充当用户名username
		user.setUsername(user.getEmail());
		boolean  res =  userService.regist(user);
		if(res) {
			response.sendRedirect("/fruits/login.jsp");
		}else {
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().print("<script>alert('regist err....')</script>");
		}
		
	}

	

}
